#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <stack>
using namespace std;

class Parenthesis
{
public:
    bool chkParenthesis(string A, int n)
    {
        if (n < 0)
        {
            return false;
        }
        if (n == 0)
        {
            return true;
        }

        stack<char> st_push;

        string::iterator it = A.begin();
        while (it != A.end())
        {
            if (*it == '(')
            {
                st_push.push(*it);
            }
            else if (*it == ')')
            {
                if (st_push.empty())
                {
                    return false;
                }
                else
                {
                    st_push.pop();
                }
            }
            else
            {
                return false;
            }
            it++;
        }
        if (st_push.empty())
        {
            return true;
        }
        else
        {
            return false;
        }
        // write code here
    }
};

class Solution 
{
public:
    string convert(string s, int numRows) 
    {
        if (numRows < 2)
        {
            return s;
        }
        vector<string> rows(numRows);
        int i = 0, flag = -1;
        for (char c : s)
        {
            rows[i].push_back(c);
            if (i == 0 || i == numRows - 1)
            {
                flag = -flag;
            }
            i += flag;
        }
        string res;
        for (const string& row : rows)
        {
            res += row;
        }
        return res;
    }
};

int main()
{
    int count = 0;
    int n = 0;
    cin >> n;
    if (n <= 3)
    {
        cout << 0 << endl;
        return 0;
    }

    vector<int> a;
    a.push_back(0);
    a.push_back(1);
    a.push_back(1);

    int i = 0;
    int min = 0, max = 0;
    for (i = 3;; i++)
    {
        a.push_back(a[i - 1] + a[i - 2]);
        if (a[i] > n)
        {
            max = a[i];
            min = a[i - 1];
            break;
        }
    }
    if (max - n > n - min)
    {
        min = n - min;
    }
    else
    {
        min = max - n;
    }
    cout << min;
    return 0;
}